home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / TextEditorSemIntf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-13  |  5.2 KB  |  218 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TextEditorSemIntf.cpp
  3.  
  4.     Contains:    TextEditor Apple Event interface
  5.  
  6.     Written by:    Steve Smith
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11.  
  12. #define VARIABLE_MACROS
  13. #define TextEditorSemIntf_Class_Source
  14.  
  15. #ifndef _COMPILERDEFS_
  16. #include "CompDefs.h"
  17. #endif
  18.  
  19. // -- OpenDoc Utilities --
  20.  
  21. #ifndef _EXCEPT_
  22. // Exceptions define several important macros (e.g. CHECKENV)
  23. // which are used in the SOM method dispatch glue. If Except.h
  24. // is not included early enough, exceptions may not be thrown
  25. // correctly when returning from a SOM method with "ev" parameter set.
  26. #include <Except.h>
  27. #endif
  28.  
  29. // -- TextEditorSemIntf Includes --
  30.  
  31. #ifndef SOM_TextEditorSemIntf_xih
  32. #include "TextEditorSemIntf.xih"
  33. #endif
  34.  
  35. // -- TextEditor Includes --
  36.  
  37. #ifndef SOM_SampleCode_TextEditor_xh
  38. #include "TextEditor.xh"
  39. #endif
  40.  
  41. #ifndef _TEXTEDITORGLOBALS_
  42. #include "TextEditorGlobals.h"
  43. #endif
  44.  
  45. #ifndef _TEXTEDITORUTILS_
  46. #include "TextEditorUtils.h"
  47. #endif
  48.  
  49. // -- Textension Includes --
  50.  
  51. #ifndef _TSMTextension_
  52. #include "TSMTextension.h"
  53. #endif
  54.  
  55. // -- OpenDoc Includes --
  56.  
  57. #ifndef SOM_ODPart_xh
  58. #include <Part.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODFacet_xh
  62. #include <Facet.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODSession_xh
  66. #include <ODSessn.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODArbitrator_xh
  70. #include <Arbitrat.xh>
  71. #endif
  72.  
  73. #ifndef SOM_ODOSLToken_xh
  74. #include <ODOSLTkn.xh>
  75. #endif
  76.  
  77. #ifndef SOM_ODAppleEvent_xh
  78. #include <ODAplEvt.xh>
  79. #endif
  80.  
  81. // -- OpenDoc Utilities --
  82.  
  83. #ifndef _FOCUSLIB_
  84. #include <FocusLib.h>
  85. #endif
  86.  
  87. #ifndef _ODDESUTL_
  88. #include <ODDesUtl.h>
  89. #endif
  90.  
  91. #ifndef _ODUTILS_
  92. #include <ODUtils.h>
  93. #endif
  94.  
  95. #ifndef _TEMPOBJ_
  96. #include <TempObj.h>
  97. #endif
  98.  
  99. // -- Toolbox Includes --
  100.  
  101. #ifndef __APPLEEVENTS__
  102. #include <AppleEvents.h>
  103. #endif
  104.  
  105. #ifndef __AEOBJECTS__
  106. #include <AEObjects.h>
  107. #endif
  108.  
  109. #ifndef __AEPACKOBJECT__
  110. #include <AEPackObject.h>
  111. #endif
  112.  
  113. #ifndef __TEXTSERVICES__
  114. #include <TextServices.h>
  115. #endif
  116.  
  117. #pragma segment TextEditorSemanticInterface
  118.  
  119. //------------------------------------------------------------------------------
  120. // Method:        RegisterTextension
  121. // Origin:        TextEditorSemIntf
  122. //------------------------------------------------------------------------------
  123. SOM_Scope void  SOMLINK TextEditorSemIntf__RegisterTextension(TextEditorSemIntf *somSelf, Environment *ev,
  124.         ODPtr textension)
  125. {
  126.     TextEditorSemIntfData *somThis = TextEditorSemIntfGetData(somSelf);
  127.     TextEditorSemIntfMethodDebug("TextEditorSemIntf","RegisterTextension");
  128.  
  129.     _fTextension = (CTSMTextension*) textension;
  130. }
  131.  
  132. //------------------------------------------------------------------------------
  133. // Method:        somInit
  134. // Origin:        SOMObject
  135. //------------------------------------------------------------------------------
  136. SOM_Scope void  SOMLINK TextEditorSemIntf__somInit(TextEditorSemIntf *somSelf)
  137. {
  138.     TextEditorSemIntfData *somThis = TextEditorSemIntfGetData(somSelf);
  139.     TextEditorSemIntfMethodDebug("TextEditorSemIntf","somInit");
  140.     
  141.     _fTextension = kODNULL;
  142. }
  143.  
  144. //------------------------------------------------------------------------------
  145. // Method:        somUninit
  146. // Origin:        SOMObject
  147. //------------------------------------------------------------------------------
  148. SOM_Scope void  SOMLINK TextEditorSemIntf__somUninit(TextEditorSemIntf *somSelf)
  149. {
  150.     TextEditorSemIntfMethodDebug("TextEditorSemIntf","somUninit");
  151. }
  152.  
  153. //------------------------------------------------------------------------------
  154. // Method:        CallEventHandler
  155. // Origin:        ODSemanticInterface
  156. //------------------------------------------------------------------------------
  157. SOM_Scope void  SOMLINK TextEditorSemIntf__CallEventHandler(TextEditorSemIntf *somSelf, Environment *ev,
  158.         ODPart* thePart,
  159.         ODAppleEvent* theODAppleEvent,
  160.         ODAppleEvent* reply)
  161. {
  162.     TextEditorSemIntfData *somThis = TextEditorSemIntfGetData(somSelf);
  163.     TextEditorSemIntfMethodDebug("TextEditorSemIntf","CallEventHandler");
  164.     
  165.     SOM_TRY
  166.     
  167.         AppleEvent    aeEvent = {typeNull, NULL};
  168.         AppleEvent    aeReply = {typeNull, NULL};
  169.         TempODFrame    keyFrame = kODNULL;
  170.         ODPart*        realPart = kODNULL;
  171.         
  172.         ODVolatile(realPart);
  173.     
  174.         TRY
  175.             keyFrame = ODGetSession(ev, thePart)->GetArbitrator(ev)
  176.                             ->AcquireFocusOwner(ev, gGlobals->fKeyFocus);
  177.                                     
  178.             CFrameInfo*    frameInfo = (CFrameInfo*) keyFrame->GetPartInfo(ev);
  179.             ODFacet* facet = frameInfo->GetActiveFacet();
  180.             
  181.             // Focus for drawing because Textension will draw the inline hole
  182.             // feedback.
  183.             CFocus intiateDrawing(ev, facet);
  184.     
  185.             THROW_IF_ERROR( ODDescToAEDesc(theODAppleEvent, &aeEvent) );
  186.             THROW_IF_ERROR( ODDescToAEDesc(reply, &aeReply) );
  187.             
  188.             // Let Textension handle the Apple Event.
  189.             THROW_IF_ERROR(_fTextension->ProcessAppleEvent(&aeEvent, &aeReply, 0));
  190.             
  191.             THROW_IF_ERROR( AEDescToODDesc(&aeReply, reply) );
  192.             
  193.             // If the event was handled, dirty the document.
  194.             // The part passed to this method is actually the partwrapper for
  195.             // the editor, so we need to get the "real" part to call methods
  196.             // of it.
  197.             realPart = thePart->GetRealPart(ev);
  198.             ((SampleCode_TextEditor*) realPart)->HandleChange(ev);
  199.             thePart->ReleaseRealPart(ev);
  200.             
  201.         CATCH_ALL
  202.             if ( realPart )
  203.                 thePart->ReleaseRealPart(ev);
  204.             AEDisposeDesc(&aeEvent);
  205.             AEDisposeDesc(&aeReply);
  206.             RERAISE;
  207.         ENDTRY
  208.         
  209.         AEDisposeDesc(&aeEvent);
  210.         AEDisposeDesc(&aeReply);
  211.         
  212.     SOM_CATCH_ALL
  213.     SOM_ENDTRY
  214. }
  215.  
  216.  
  217.  
  218.